<?php

namespace App\Kuafu\Order\Model;

use App\Kuafu\Base\Model\Traits\KfSoftDeletes;

use App\Kuafu\Base\Model\Traits\KfSplitRelation;
use App\Kuafu\Base\Model\Traits\KfUid;
use App\Kuafu\Coupon\Enum\CouponCodeEnum;
use App\Kuafu\Coupon\Enum\CouponEnum;
use App\Kuafu\CouponExt\Enum\CouponExtEnum;
use App\Kuafu\CouponExt\Model\OrderCouponExtSplitModel;
use App\Kuafu\Customer\Model\CustomerModel;
use App\Kuafu\Order\Enum\CodeEnum;
use App\Kuafu\Order\Service\OrderCalcService;
use App\Kuafu\Order\Service\OrderDb;
use App\Kuafu\Order\Service\OrderService;
use App\Kuafu\Order\Service\OrderTable;
use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Pay\Model\PayStreamModel;
use App\Kuafu\Pay\Model\RefundStreamModel;
use App\Kuafu\Shop\Model\Shop;
use App\Kuafu\User\Exceptions\UserException;
use App\Kuafu\WaiMai\Enum\WaiMaiDBEnum;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\DB;

class OrderUserInfoSplitModel extends BaseModel
{
    use KfSoftDeletes, KfUid, KfSplitRelation;

    public    $incrementing = false;
    protected $fillable     = [
        'id',
        'orderId',
        'brandId',
        'shopId',
        'provinceName',
        'cityName',
        'countyName',
        'provinceCode',
        'cityCode',
        'countyCode',
        'detailInfo',
        'telNumber',
        'userName',
    ];
    protected $hidden       = [];

    private static $startAt, $endAt;

    public static string $tableName;
    public static string $connectionName;
    public static string $shopId;

    public static function suffix($shopId)
    {
        if (is_int($shopId) && $shopId < 0) {
            $shopId = 0;
        }

        self::$connectionName = OrderDb::orderDbConnection($shopId);
        self::$tableName      = OrderTable::orderUserInfoTableName($shopId);
        self::$shopId         = $shopId;
        return new static;
    }

    public function getTable()
    {
        return self::$tableName ?? parent::getTable();
    }

    public function getConnectionName()
    {
        return self::$connectionName ?? parent::getConnectionName();
    }

    /**
     * 插入主表数据
     *
     * @param $data
     */
    public static function insertOrderUserInfo($data)
    {
        self::query()->insert($data);
    }
}
